﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace KuPeiXun.Utility
{
    /// <summary>
    /// linq to entity帮助类
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// ===============================================================
    /// 作者：邹学良 
    /// 时间：2013-03-21
    /// 描述：创建
    /// 历史：无
    /// ===============================================================
    public class LinqToEntityHepler<T>
    {
        #region 通过分页获取相应的linq对象
        /// <summary>
        /// 通过分页获取相应的linq对象
        /// </summary>
        /// <param name="linq">linq对象</param>
        /// <param name="page">分页条件</param>
        /// <returns></returns>
        public static IQueryable<T> GetEntitysByPaging(IQueryable<T> linq, Entity.PagingParameter page)
        {
            try
            {
                IQueryable<T> list = null;
                switch (page.IsPaging)
                {
                    case false:
                        list = linq;
                        break;
                    case true:
                        list = linq.Skip((page.Page - 1) * page.Row)
                            .Take(page.Row);
                        break;
                }
                return list;
            }
            catch (Exception ex)
            {
                throw new LogHepler(ex);
            }
        }
        #endregion
    }
}
